home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / net / tf02.lha / TinyFugue / tf-lib / lisp.tf < prev    next >
Text File  |  1995-08-12  |  1KB  |  59 lines

  1. ;;; Lisp-like macros
  2. ; These macros return values via /echo.  Use $() command subs to catch output.
  3.  
  4. /~loaded lisp.tf
  5.  
  6. /def -i car = /echo - %1
  7. /def -i cdr = /echo - %-1
  8. /def -i cadr = /echo - %2
  9. /def -i cddr = /echo - %-2
  10. /def -i caddr = /echo - %3
  11. /def -i cdddr = /echo - %-3
  12.  
  13. /def -i length = /echo %#
  14.  
  15. /def -i reverse = \
  16.     /let result=%1%;\
  17.     /while (shift(), {#}) \
  18.         /let result=%1 %result%;\
  19.     /done%;\
  20.     /echo - %result
  21.  
  22. /def -i mapcar = \
  23.     /let cmd=%1%; \
  24.     /while (shift(), {#}) \
  25.         /eval %cmd %%1%; \
  26.     /done
  27.  
  28. /def -i maplist = \
  29.     /let cmd=%1%;\
  30.     /while (shift(), {#}) \
  31.         /eval %cmd %%*%;\
  32.     /done
  33.  
  34. /def -i remove = \
  35.     /let word=%1%;\
  36.     /let result=%;\
  37.     /while (shift(), {#}) \
  38.         /if (word !~ {1}) \
  39.             /let result=%{result} %{1}%;\
  40.         /endif%;\
  41.     /done%;\
  42.     /echo - %{result}
  43.  
  44.  
  45. ;; Remove all duplicate items from list.
  46. ;; Note that the speed of this macro is O(N^2), so it is very slow on
  47. ;; long lists.
  48.  
  49. ;/def -i unique = \
  50. ;    /if ( {#} > 1 ) \
  51. ;        /echo - %1 $(/unique $(/remove %1 %-1))%;\
  52. ;    /else \
  53. ;        /echo - %1%;\
  54. ;    /endif
  55.  
  56. /def -i unique = \
  57.     /echo - %1 $[{#} > 1 ? $(/unique $(/remove %1 %-1)) : ""]
  58.  
  59.